package com.ddpt.platform.common.base;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

import java.util.List;

@Data
public class PageResponse<T> extends BaseEntity {

    private Long current;

    private Long size;

    private Long total;

    private List<T> records;

    private Long pages;

    public PageResponse(PageRequest pageRequest, List<T> records, Long total) {
        this.current = pageRequest.getCurrent();
        this.size = pageRequest.getSize();
        this.records = records;
        this.total = total;
        Long tempPages = total/size;
        this.pages = total % size == 0 ? tempPages : (tempPages + 1);
    }

    public PageResponse(Long current,Long size,List<T> records, Long total) {
        this.current = current;
        this.size = size;
        this.records = records;
        this.total = total;
        Long tempPages = total/size;
        this.pages = total % size == 0 ? tempPages : (tempPages + 1);
    }

    public PageResponse(IPage<T> page) {
        this.current = page.getCurrent();
        this.size = page.getSize();
        this.records = page.getRecords();
        this.pages = page.getPages();
    }
}
